import * as KoaRouter from 'koa-router';
import * as user from '../controller/user';
import { restify, APIErrorHandler } from '../plugin/restful';
import { verify, auth } from '../plugin/jwt';
import config from '../config';

const router = new KoaRouter();
router.prefix(config.prefix.api);
// 仅对该路由增加中间件
router.use(restify);
router.use(APIErrorHandler);

router.get('/users', auth, user.getList);
router.get('/user/:id', auth, user.getOne);
router.post('/user', user.create);
router.put('/user/:id', user.update);
router.delete('/user/:id', user.del);
router.get('/token', user.getToken);

export default router;
